package com.huawei.hwid.core.d;

import android.content.Context;
import android.os.Build;
import android.os.Build.VERSION;
import android.text.TextUtils;
import com.huawei.hwCloudJs.d.d;
import com.huawei.hwid.core.c.a;
import com.huawei.hwid.core.d.b.e;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.UUID;

public class n {
    private static int a = 20;
    private static String b = "";
    private static String c = "";

    public static String a() {
        String str = "";
        str = Build.MODEL;
        if (TextUtils.isEmpty(str)) {
            str = d.b;
        }
        try {
            str = URLEncoder.encode(str, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.d("TerminalInfo", "in getTerminalType Unsupported encoding exception", true);
        }
        return str;
    }

    public static String b() {
        String str = "";
        str = Build.MODEL;
        if (TextUtils.isEmpty(str)) {
            return d.b;
        }
        return str;
    }

    public static String a(Context context) {
        String b = b(context);
        if (b == null || "NULL".equals(b)) {
            return a(context, 0);
        }
        return b;
    }

    public static String b(Context context) {
        String c = c(context);
        if (!b.f() || b.e() || "NULL".equals(c)) {
            return c;
        }
        return c + "_" + b.d();
    }

    public static String c(Context context) {
        if (TextUtils.isEmpty(b) || !b.a(b) || b.length() > a) {
            String a = a.a(context).a("DEVID_1", "");
            if (!TextUtils.isEmpty(a)) {
                if (!b.a(a) || b.length() > a) {
                    e.d("TerminalInfo", "cbcDecrypter devid failed!!!", true);
                    a.a(context).a("DEVID_1");
                    b = null;
                } else {
                    a(a);
                    return a;
                }
            }
            if (TextUtils.isEmpty(b) || d.b.equalsIgnoreCase(b)) {
                return a(context, 0);
            }
        }
        return b;
    }

    private static synchronized void a(String str) {
        synchronized (n.class) {
            if (str == null) {
                b = "";
            } else {
                b = str;
            }
        }
    }

    public static String a(Context context, int i) {
        if (i >= 2) {
            return "NULL";
        }
        int i2 = i + 1;
        if (TextUtils.isEmpty(c)) {
            b(a.a(context).a("UUID", ""));
            if (TextUtils.isEmpty(c)) {
                b(UUID.randomUUID().toString());
                if (TextUtils.isEmpty(c)) {
                    return "NULL";
                }
                a.a(context).b("UUID", c);
            }
        }
        if (!TextUtils.isEmpty(c) && (c.length() > 40 || !b.a(c))) {
            c = "";
            a.a(context).a("UUID");
            c = a(context, i2);
        }
        return c;
    }

    private static synchronized void b(String str) {
        synchronized (n.class) {
            c = str;
        }
    }

    public static String c() {
        return VERSION.RELEASE;
    }
}
